package com.syzg.view.tags;

import java.io.IOException;

import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.JspFragment;
import javax.servlet.jsp.tagext.SimpleTagSupport;

import com.syzg.base.login.model.LoginObject;
import com.syzg.common.util.SystemUtil;

public class PermissionTag extends SimpleTagSupport {
	private String module;
	private String operation;

	public String getModule() {
		return module;
	}

	public void setModule(String module) {
		this.module = module;
	}

	public String getOperation() {
		return operation;
	}

	public void setOperation(String operation) {
		this.operation = operation;
	}

	@Override
	public void doTag() throws JspException, IOException {
		PageContext pageContext = (PageContext)getJspContext();
		HttpSession session = pageContext.getSession();
        LoginObject loginObject = SystemUtil.getLoginObject(session);
        if(loginObject != null){
            String personId = loginObject.getPersonId();
            if(SystemUtil.isAdmin(personId) || (loginObject.getPermissionList() != null && !loginObject.getPermissionList().isEmpty() || loginObject.getPermissionList().contains((new StringBuilder(String.valueOf(operation))).append("_").append(module).toString()))){
            	JspFragment jf = this.getJspBody();
            	jf.invoke(null);
            }
        }
	}
}
